package com.sudao.android.ball;

import android.app.ListActivity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

import com.sudao.android.ball.BestRecord.Record;

public class BestRecordActivity extends ListActivity {

	private static final int RECORD_COUNT = 10;
	private static final String RECORD = "record";
	private static String[] KEY_RECORDS;
	static {
		KEY_RECORDS = new String[RECORD_COUNT];
		for (int i = 0; i < RECORD_COUNT; i++) {
			KEY_RECORDS[i] = RECORD + i;
		}
	}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

		ArrayList<Record> records = (ArrayList<Record>) BestRecord.loadRecordReverse(this);
		if (records.isEmpty())
			return;

		ArrayList<String> infos = new ArrayList<String>();
		for (int i = 0; i < records.size(); i++) {
			infos.add(records.get(i).score + getResources().getString(R.string.record_date) + records.get(i).date);
		}
        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, infos));

        AnimationSet set = new AnimationSet(true);
        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(50);
        set.addAnimation(animation);
        animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
        );
        animation.setDuration(100);
        set.addAnimation(animation);

        LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
        ListView listView = getListView();
        listView.setLayoutAnimation(controller);
    }
}
